<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>损溢抹平</title>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>损溢抹平</cite>
        </a>
      </span>
</div>
<div class="x-body">
	
	<!-- 列表页上方的搜索栏 及 列表 -->
	<div style="margin-bottom: 18px">
		<div class="layui-inline">
			<table>
				<tr>
					<td>
						<input class="layui-input" name="code" id="codec" placeholder="请输入条码" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
						<input class="layui-input" name="materielNum" id="materielNum" placeholder="请输入SAP/QAD" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
					</td>
			</table>
		</div>
		<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
	</div>
	<!-- <xblock>
		<button class="layui-btn layui-btn-danger" id="dels"><i class="layui-icon layui-icon-delete"></i>批量抹平</button>
	</xblock> -->
	<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
	
	 <script type="text/html" id="rowToolbar">
        <a class="layui-btn layui-btn-xs" lay-event="smoothing"><i class="layui-icon layui-icon-ok"></i>抹平差异</a>
    </script>
</div>

<script type="text/javascript">
    var table;
    layui.use(['table','layer','upload','form','laydate'], function(){
        table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;

        var $ = layui.jquery, active = {
            reload:function () {
                var codec = $.trim($("#codec").val());
                var materielNum = $.trim($("#materielNum").val());
                table.reload('contenttable',{
                    method:'get',
                    where:{
                    	code:codec,
                    	materiel_num:materielNum
                    }
                    ,page: {
                    	//重新从第 1 页开始
                        curr: 1
                    }
                });
            }
        }
    	
      	//点击行checkbox选中
	    $(document).on("click",".layui-table-body table.layui-table tbody tr", function () {
	        var index = $(this).attr('data-index');
	        var tableBox = $(this).parents('.layui-table-box');
	        //存在固定列
	        if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length>0) {
	            tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
	        } else {
	            tableDiv = tableBox.find(".layui-table-body.layui-table-main");
	        }
	        var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
	        if (checkCell.length>0) {
	            checkCell.click();
	        }
	    });
	
	    $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
	        e.stopPropagation();
	    });
        
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        /* 需抹平列表 */
        table.render({
            elem: '#tableList'
            ,url:'${pageContext.request.contextPath }/inventory/queryCodeList.do'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,toolbar: '#toolbar'
            ,cols: [[
                    {field:'id',title:'序号',sort: true,width: 60,type:'numbers',align:'center'},
                    {field: 'materiel_num',title: 'SAP/QAD',align:'center'},
                    {field: 'materiel_name',title: '物料名称',align:'center'},
                    {field: 'code',title: '条码',align:'center'},
                    {field: 'theory_num',title: '库存',align:'center', templet: function(d){
						if(d.theory_num == 0){
							return 0;
						} else {
							return d.theory_num;
						}
					}},
                    {field: 'reality_num',title: '实际',align:'center', templet: function(d){
						if(d.reality_num == 0){
							return 0;
						} else {
							return d.reality_num;
						}
					}},
                    {field: 'diff_num',title: '差异',align:'center', templet: function(d){
						if(d.diff_num == 0){
							return 0;
						} else {
							return d.diff_num;
						}
					}},
					{fixed:'right',unresize: true, title:'操作', toolbar: '#rowToolbar', align: 'center'}
                ]]
            ,page: true
            ,done : function(){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold'
                })
            }
        });
        
        //监听收货计划管理的编辑事件
        table.on('tool(tableList)', function(obj){
            var data = obj.data;
            if(obj.event === 'smoothing'){
            	 layer.confirm('确定抹平吗？', function(index){
                	$.ajax({
                        type:'post',
                        data:data,
                        url:'${pageContext.request.contextPath }/inventory/smoothing.do',
                        dataType: 'JSON',
                        async: false,
                        success:function (data) {
                            if(data > 0){
                            	toastr.success('操作成功');
                            }else{
                            	toastr.error('操作失败');
                            }
                            layer.closeAll();
                            table.reload('contenttable',{
                                method:'get',
            	                page: {
            	                    curr: 1//重新从第 1 页开始
            	                }
                            });
                        }
                    });
            	 });
            }
        });
        
    toastrStyle();
   });  
</script>
</body>
</html>